package com.zoe.onelink.upms.common.entity;

import lombok.Data;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.OAuth2Request;

import java.io.Serializable;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2018</p>
 * <p>公司: 智业软件</p>
 *
 * @author LinHongKai
 * @date 2022-06-17 15:03
 */
@Data
public class AuthInfo implements Serializable {

    private static final long serialVersionUID = 1614274137064195193L;

    public AuthInfo() {}

    public AuthInfo(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        this.accessToken = accessToken;
        this.oAuth2Request = authentication.getOAuth2Request();
        this.userAuthentication = authentication.getUserAuthentication();
    }

    private OAuth2AccessToken accessToken;

    private OAuth2Request oAuth2Request;

    private Authentication userAuthentication;

    public OAuth2Authentication buildAuthentication() {

        OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request, userAuthentication);
        oAuth2Authentication.setAuthenticated(true);
        return oAuth2Authentication;
    }
}
